package com.gxg.dao;

import com.gxg.entities.Video;
import com.gxg.repository.VideoRepository;
import com.sun.media.jfxmedia.events.VideoTrackSizeListener;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.data.domain.Pageable;
import org.springframework.stereotype.Repository;
import org.springframework.util.StringUtils;

import javax.validation.constraints.Null;

import java.util.List;

/**
 * By 李朋飞
 **/
@Repository
public class VideoDao {
    @Autowired
    VideoRepository videoRepository;


    public Video save(Video video){
        return videoRepository.save(video);
    }

//    /**
//     * 根据视频的标题删除视频
//     * @param videoTitle
//     */
//    public String videoDelete(String videoTitle) {
//        Video video = videoRepository.findByVideoTitle(videoTitle);
//        if (!StringUtils.isEmpty(video)){
//            videoRepository.deleteByVideoTitle(videoTitle);
//            return video.getVideoName();
//        }else {
//            return "";
//        }
//
//    }
//


    /**
     * 通过视频路径删除视频
     * @param localUrl
     * @return
     */
    public String deleteByLocalUrl(String localUrl){
        videoRepository.deleteByVideoLocalUrl(localUrl);
        return "删除成功";
    }


    /**
     * 获取所有视频
     * @return
     */
    public List<Video> getVideo(){
        return videoRepository.findAll();
    }

    /**
     * 通过视频路径获得老师的ID
     * @param webUrl
     * @return
     */
    public List<Video> getVideoByWebUrl(String webUrl) {
       return videoRepository.findByVideoWebUrl(webUrl);
    }

    /**
     * 通过视频类别获取视频
     * @param videoClass
     * @return
     */
    public List<Video> getVideoByVideoClass(String videoClass){
        return videoRepository.findByVideoClass(videoClass);
    }

    public List<Video> findByTeacherIdAndParentTitle(String teacherId, String parentTitle, Pageable pageable){
        return videoRepository.findByTeacherIdAndParentTitle(teacherId,parentTitle,pageable).getContent();
    }
    public int countByTeacherIdAndParentTitle(String teacherId,String parentTitle){
        return videoRepository.countByTeacherIdAndParentTitle(teacherId,parentTitle);
    }

    public int getVideoNumberByTeacherId(String teacherId){
        return videoRepository.countByTeacherId(teacherId);
    }
    public List<Video> findByChildImgWebUrl(String childImgWebUrl){
        return videoRepository.findByChildImgWebUrl(childImgWebUrl);
    }

    public List<Video> getVideoByTeacherId(String teacherId){
        return videoRepository.findByTeacherId(teacherId);
    }
}
